﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace Jmr.Entity.Poco.Silverlight
{
	public class DynamicDataAdapter
	{
		public static void Fill(DataTable source, DynamicTable destination)
		{
			foreach (DataColumn column in source.Columns)
				destination.Columns.Add(column.ColumnName);

			for (int i = 0; i < source.Rows.Count; i++)
			{
				DynamicRow destRow = new DynamicRow();
				foreach (var col in destination.Columns)
				{
					destRow.Columns.Add(new DynamicColumn { Name = col});
					destRow.Values.Add(new DynamicColumnValue { Name = col, Value = source.Rows[i][col]});
				}
				destination.Rows.Add(destRow);
			}
		}
	}
}
